package org.jw.wishlist.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
 * @author Jiawei Zhao
 */
@MappedSuperclass
@SuperBuilder
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Schema(description = "实体类抽象父类")
public abstract class AbstractEntity {

  @Schema(description = "主键id")
  @Id
  private Long id;

  @Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (obj == this) {
      return true;
    }
    if (obj.getClass() != getClass()) {
      return false;
    }
    AbstractEntity rhs = (AbstractEntity) obj;
    return new EqualsBuilder()
        .appendSuper(super.equals(obj))
        .append(id, rhs.id)
        .isEquals();
  }

  @Override
  public int hashCode() {
    return new HashCodeBuilder()
        .append(id)
        .toHashCode();
  }

}
